package day03;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoJsp extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		resp.sendRedirect("http://baidu.com");
		//获取IP地址
		String remoteAddr = req.getRemoteAddr();

		//获取当前时间
		Date d=new Date();
		DateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date=formatter.format(d);
		String content=new String(remoteAddr+"\t"+date);
		//req.getParameter(name)  但是没有req.setParameter()方法
		//所以可以用req.setAttribute()
		req.setAttribute("message", content);
		
		//请求转发
		req.getRequestDispatcher("welcome.jsp").forward(req, resp);
		//
//		System.out.println(content);

	}
}
